export const defaultUnit = '件';

export function getUnitText(record, options) {
  const list = [];
  const { purUnit, saleUnit, csmUnit } = record;

  options ||= {};
  const suffix = options.suffix || '';

  if (purUnit) {
    list.push(`进货${suffix}：${purUnit}`);
  }

  if (saleUnit) {
    list.push(`售卖${suffix}：${saleUnit}`);
  }

  if (csmUnit) {
    list.push(`消耗${suffix}：${csmUnit}`);
  }

  return list.join('；');
}

export function getConvertUnitText(record) {
  const { saleUnit, saleToCsm, csmUnit } = record;

  if (!saleUnit || !csmUnit) {
    return '';
  }

  return `1${saleUnit || defaultUnit} = ${saleToCsm ?? 1}${csmUnit || defaultUnit}`;
}

export function getValidDesc({ validType, validDate, validDateUnit, updateTime }) {
  if (validType === '40') {
    return '永久有效';
  }

  const prefix =
    validType === '10'
      ? '自购买之日起'
      : validType === '20'
        ? '自首次消费起'
        : validType === '30'
          ? ''
          : '';
  const suffix = (validDate || 0) + (validDateUnit || '日') + '有效';

  return prefix + suffix;
}
